import request from '@/utils/request'
import { notification } from 'ant-design-vue'
import { officeApiUrl, commonApiUrl, } from '@/api/config.js'

const errorTips = '请求失败，请稍后重试！'
const prefix = officeApiUrl
const commonPrefix = commonApiUrl

export async function handleRequest(options, config = {}) {
  const p = request({
    timeout: 1000 * 60 * 5,
    ...options,
    url: `${config.useCommon ? commonPrefix : prefix}${options.url}` // useCommon：是否使用通用服务
  })
  try {
    const res = await p
    if ((res.code !== 200 && res.data && res.data.code !== 200) || (res.status === 200 && !res.data)) {
      // notification.error({
      //   message: '提示',
      //   description: (res.data && res.data.message) || errorTips
      // })
      throw new Error((res.data && res.data.message) || errorTips)
    } else {
      return [null, res]
    }
  } catch (e) {
    return [e, null]
  }
}
